@include('Admin.public.head')
<style type="text/css">
    #my-popup2 {
        max-height: 200px;
    }
    #my-popup1 {
        max-height: 200px;
    }
    #my-popup {
        max-height: 600px;
    }
    
    .red2 {
        color: #d93c37;
        font-size: 14px;
    }
</style>
<body>
@include('Admin.public.menu')
<div class=" admin-content" id="app">
    {{ csrf_field() }}
    <div class="daohang">
    </div>
    <!--添加模态框1-->
    <div class="am-popup am-popup-inner" id="my-popup1">
        <div class="am-popup-hd">
            <h4 class="am-popup-title">添加股东分红</h4>
            <span data-am-modal-close
                  class="am-close">&times;</span>
        </div>
        <div class="am-popup-bd">
            <form class="am-form">
                    <div class="am-form-group am-cf">
                        <label class="sr-only" for="district1">股东分红金额</label>
                        <div class="you">
                            <input type="number" class="am-form-field" maxlength="11" v-model="moneybl"
                                placeholder="请输入股东分红金额" :readonly="readonly">
                        </div>
                    </div>
                    <div class="am-text-center" style="margin-top: 20px ">
                    <a type="button" v-on:click="handleAdd1()" class="am-btn am-btn-primary">提交</a>
                </div>
            </form>
        </div>
    </div>
 <!--添加模态框2-->
    {{--<div class="am-popup am-popup-inner" id="my-popup2">--}}
        {{--<div class="am-popup-hd">--}}
            {{--<h4 class="am-popup-title">添加DT股东分红</h4>--}}
            {{--<span data-am-modal-close--}}
                  {{--class="am-close">&times;</span>--}}
        {{--</div>--}}
        {{--<div class="am-popup-bd">--}}
            {{--<form class="am-form">--}}
                    {{--<div class="am-form-group am-cf">--}}
                        {{--<label class="sr-only" for="district1">DT股东分红金额</label>--}}
                        {{--<div class="you">--}}
                            {{--<input type="number" class="am-form-field" maxlength="11" v-model="moneydt"--}}
                                {{--placeholder="请输入DT股东分红金额" :readonly="readonly">--}}
                        {{--</div>--}}
                    {{--</div>--}}
                    {{--<div class="am-text-center" style="margin-top: 20px ">--}}
                    {{--<a type="button" v-on:click="handleAdd2()" class="am-btn am-btn-primary">提交</a>--}}
                {{--</div>--}}
            {{--</form>--}}
        {{--</div>--}}
    {{--</div>--}}
<!--添加模态框-->
    <div class="am-popup am-popup-inner" id="my-popup">
        <div class="am-popup-hd">
            <h4 class="am-popup-title">@{{ subType=='edit'?'编辑股东':'添加股东' }}</h4>
            <span data-am-modal-close
                  class="am-close">&times;</span>
        </div>
        <div class="am-popup-bd">
            <form class="am-form">
                <div class="am-form-group am-cf">
                    <label class="sr-only" for="district1">账号</label>
                    <div class="you">
                        <input type="number" class="am-form-field" maxlength="11" v-model="shareholder.name"
                               placeholder="请输入入股人账号" :readonly="readonly">
                               <p class="red2">用户名:@{{ Sname }}</p>
                    </div>
                </div>
                {{--<div class="am-radio up-radio-item">--}}
                    {{--<label>--}}
                        {{--<input type="checkbox" name="doc-radio-1" value="0" v-model="shareholder.DT_shareholder">--}}
                        {{--DT内衣股东--}}
                    {{--</label>--}}
                {{--</div>--}}
                <div class="am-radio up-radio-item up-radio-item2">
                    <label>
                        <input type="checkbox" name="doc-radio-2" value="0" v-model="shareholder.shareholder">
                        股东
                    </label>
                </div>

                <div class="am-form-group am-cf" v-if="shareholder.shareholder">
                    <div class="zuo">入股金额：</div>
                    <div class="you">
                        <input type="number" class="am-form-field" v-model="shareholder.equity_price2"
                               placeholder="请输入入股金额">
                        <!-- <p class="am-form-help">会员等级</p> -->
                    </div>
                </div>
                {{--<div class="am-form-group am-cf" v-if="shareholder.DT_shareholder">--}}
                    {{--<div class="zuo">DT入股金额：</div>--}}
                    {{--<div class="you">--}}
                        {{--<input type="text" class="am-form-field" v-model="shareholder.equity_price"--}}
                               {{--placeholder="请输入入股金额">--}}
                        {{--<!-- <p class="am-form-help">会员等级</p> -->--}}
                    {{--</div>--}}
                {{--</div>--}}
                <div class="am-text-center" style="margin-top: 20px ">
                    <a type="button" v-on:click="doApply()" class="am-btn am-btn-primary">提交</a>
                </div>
            </form>
        </div>
    </div>
    <div class="admin-biaogelist">
        <div class="listbiaoti am-cf">
            <ul class="am-icon-users"> 股东管理</ul>
            <dl>
                <button type="button" data-am-modal="{target: '#my-popup'}"
                        class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" @click="handleAdd">
                    添加股东
                </button>
            </dl>
            {{--<dl>--}}
                {{--<button type="button" data-am-modal="{target: '#my-popup1'}"--}}
                        {{--class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" @click="handleAddbl">--}}
                    {{--添加典华股东分红--}}
                {{--</button>--}}
            {{--</dl>--}}
            {{--<dl>--}}
                {{--<button type="button" data-am-modal="{target: '#my-popup2'}"--}}
                        {{--class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" @click="handleAdddt">--}}
                        {{--添加DT股东分红--}}
                {{--</button>--}}
            {{--</dl>--}}
            <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">代理商列表</a></dl>
            <!--这里打开的是新页面-->
        </div>
        <div class="am-btn-toolbars am-btn-toolbar am-kg am-cf">
            <ul>
                <li>
                    <template>
                        <el-select v-model="keyword.type" placeholder="代理类型">
                            <el-option
                                    size="medium"
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </li>
                <li>
                    <el-input v-model="keyword.keyword" class="keywords" placeholder="关键词搜索"></el-input>
                </li>
                <li>
                    <el-button type="primary" v-on:click="changeClick()">搜索</el-button>
                </li>
                <li>
                    <el-button type="danger" v-on:click="resetOrder()">重置</el-button>
                </li>
            </ul>
        </div>


        <form class="am-form am-g">
            <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                <tr class="am-success">
                    <th class="table-title">账号</th>
                    <th class="table-title">姓名</th>
                    {{--<th class="table-type">股东类型</th>--}}
                    <th class="table-date am-hide-sm-only">股东&nbsp;&nbsp;&nbsp;&nbsp;总分润金额/实际分润金额</th>
                    {{--<th class="table-date am-hide-sm-only">DT股东&nbsp;&nbsp;&nbsp;&nbsp;总分润金额/实际分润金额</th>--}}
                    <th width="130px" class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="val,index in ApplyList">
                    <td>@{{ val.name }}</td>
                    <td>@{{ val.user_name }}</td>
                    {{--<td v-if="val.DT_shareholder && val.shareholder">DT股东/宝励股东</td>--}}
                    {{--<td v-else>@{{ val.DT_shareholder?'DT股东':''}} @{{ val.shareholder?'宝励股东':'' }}</td>--}}
                    <td>@{{ val.performance.substring(0,val.performance.indexOf(".")+3) }} / @{{val.real_price2.substring(0,val.real_price2.indexOf(".")+3) }}</td>
                    {{--<td>@{{ val.DT_performance.substring(0,val.DT_performance.indexOf(".")+3) }} / @{{ val.real_price.substring(0,val.real_price.indexOf(".")+3) }}</td>--}}
                    <td style="width:250px;">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <a class="am-btn am-btn-danger am-radius" data-am-modal="{target: '#my-popup'}"
                                   v-on:click="doShareholder(val)">编辑</a>
                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <!--分页-->
            <ul class="am-pagination am-fr">
                <div class="block">
                    <el-pagination
                            background
                            :page-size="PagesData.per_page"
                            :current-page="PagesData.current_page"
                            layout="total , prev, pager, next"
                            :total="PagesData.total"
                            @prev-click="changeClick"
                            @next-click="changeClick"
                            @current-change="changeClick">
                    </el-pagination>
                </div>
            </ul>

        </form>
        <script src="{{ URL::asset('js/address/distpicker.data.js') }}"></script>
        <script src="{{ URL::asset('js/address/distpicker.js') }}"></script>
        <script>
            var app = new Vue({
                el: "#app",
                data: {
                    moneybl:"",
                    moneydt:"",
                    ApplyList: [], //股东列表
                    PagesData: [],//分页
                    options: [{
                        value: '1',
                        label: '商品股东'
                    }, {
                        value: '2',
                        label: '股东'
                    }],
                    keyword: { //关键字搜索
                        type: '',
                        keyword: '',
                    },
                    shareholder: {
                        'name': '',
                        'DT_shareholder': true,
                        shareholder: false,
                        equity_price: '', //DT入股金额
                        equity_price2: '' //宝励入股金额
                    },
                    subType: '',
                    readonly: false,
                    Sname: ''
                },
                watch: {
                    'shareholder.name': function (value) {
                        $.get("/admin/members/doShareholders", {
                            '_token': '{{csrf_token()}}',
                            class: 'findmember',
                            name: value
                        }, function (res) {
                            if (res.code) {
                                app.Sname = res.data
                            } else {
                            }
                        });
                    }
                },
                //事件
                methods: {
                    handleAddbl(){
                        app.moneybl=""
                        console.log(11)
                    },
                    handleAdddt(){
                        app.moneydt=""
                        console.log(12)
                    },
                    //选择当前页
                    changeClick: function (e) {
                        var index = layer.load(0, {
                          shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });
                        var rico = this
                        $.get("/admin/members/doShareholders", {
                            '_token': '{{csrf_token()}}',
                            class: 'select',
                            page: e,
                            keyword: app.keyword
                        }, function (res) {
                            layer.close(index);
                            if (res.code) {
                                app.ApplyList = res.data.data
                                app.PagesData = res.data
                            } else {
                                layer.msg(res.data);
                            }
                        });
                    },

                    initialize: function () {
                        var index = layer.load(0, {
                          shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });
                        var rico = this
                        //代理商列表
                        $.get("/admin/members/doShareholders", {
                            '_token': '{{csrf_token()}}',
                            class: 'select'
                        }, function (res) {
                            layer.close(index);
                            if (res.code) {
                                app.ApplyList = res.data.data
                                app.PagesData = res.data
                            } else {
                                layer.msg(res.data);
                            }
                        });

                    },
                    //代理申请
                    doApply: function () {
                        var rico = this
                        if (!app.shareholder.name) {
                            layer.msg('请输入账号')
                            return false
                        }
                        console.log(this.shareholder)
                        // if (!app.shareholder.DT_shareholder && !app.shareholder.shareholder) {
                        //     layer.msg('请选择股东类型')
                        //     return false
                        // }
                        // if (app.shareholder.DT_shareholder) {
                        //     if (!app.shareholder.equity_price) {
                        //         layer.msg('请输入DT股东入股金额')
                        //         return false
                        //     }
                        // }
                        // if (app.shareholder.shareholder) {
                        //     if (!app.shareholder.equity_price2) {
                        //         layer.msg('请输入宝励股东入股金额')
                        //         return false
                        //     }
                        // }
                        var shareholder;
                        var DT_shareholder;
                        if (app.shareholder.shareholder === false || app.shareholder.shareholder == 0 || app.shareholder.shareholder == null) {
                            shareholder = 0
                        } else {
                            shareholder = 1
                        }
                        if (app.shareholder.DT_shareholder === false || app.shareholder.DT_shareholder == 0 || app.shareholder.DT_shareholder == null) {
                            DT_shareholder = 0
                        } else {
                            DT_shareholder = 1
                        }
                        var sendData = {}
                        if (app.subType === 'add') {
                            if (!app.shareholder.shareholder) {
                                sendData = {
                                    name: app.shareholder.name,
                                    DT_shareholder: DT_shareholder,
                                    equity_price: app.shareholder.equity_price,
                                }
                            } else if (!app.shareholder.DT_shareholder) {
                                sendData = {
                                    name: app.shareholder.name,
                                    shareholder: shareholder,
                                    equity_price2: app.shareholder.equity_price2,
                                }
                            } else {
                                sendData = {
                                    name: app.shareholder.name,
                                    DT_shareholder: DT_shareholder,
                                    shareholder: shareholder,
                                    equity_price: app.shareholder.equity_price,
                                    equity_price2: app.shareholder.equity_price2,
                                }
                            }
                            $.post("/admin/members/doShareholders", {
                                '_token': '{{csrf_token()}}',
                                'class': 'add',
                                shareholder: sendData
                            }, function (res) {
                                if (res.code) {
                                    layer.msg(res.data);
                                    $('#my-popup').modal('close')
                                    rico.initialize();
                                } else {
                                    layer.msg(res.data);
                                }
                            });
                        } else {
                            $.post("/admin/members/doShareholders", {
                                '_token': '{{csrf_token()}}',
                                'class': 'edit',
                                shareholder: {
                                    name: app.shareholder.name,
                                    DT_shareholder: DT_shareholder,
                                    shareholder: shareholder,
                                    equity_price: app.shareholder.equity_price,
                                    equity_price2: app.shareholder.equity_price2,
                                }
                            }, function (res) {
                                if (res.code) {
                                    layer.msg(res.data);
                                    $('#my-popup').modal('close')
                                    rico.initialize();
                                } else {
                                    layer.msg(res.data);
                                }
                            });
                        }

                    },
                    handleAdd: function () {
                        app.subType = 'add'
                        app.readonly = false
                        app.Sname = ''
                        app.shareholder.name = ''
                        app.shareholder.DT_shareholder = false
                        app.shareholder.shareholder = false
                        app.shareholder.equity_price = ''
                        app.shareholder.equity_price2 = ''
                    },
                    handleAdd1(){
                        var _this=this
                        $.post("/admin/members/doShareholders", {
                                '_token': '{{csrf_token()}}',
                                 class:'dividend',
                                 money:_this.moneybl
                            }, function (res) {
                                if (res.code) {
                                    layer.msg(res.data);
                                    $('#my-popup').modal('close')
                                    // rico.initialize();
                                } else {
                                    layer.msg(res.data);
                                }
                            });
                    },
                    handleAdd2(){
                        var _this=this
                        $.post("/admin/members/doShareholders", {
                                '_token': '{{csrf_token()}}',
                                class:'dt_dividend',
                                money:_this.moneydt
                            }, function (res) {
                                if (res.code) {
                                    layer.msg(res.data);
                                    $('#my-popup').modal('close')
                                    // rico.initialize();
                                } else {
                                    layer.msg(res.data);
                                }
                            });
                    },
                    //编辑代理
                    doShareholder: function (data) {
                        app.subType = 'edit'
                        app.readonly = true
                        app.shareholder.name = data.name
                        app.shareholder.DT_shareholder = data.DT_shareholder
                        app.shareholder.shareholder = data.shareholder
                        app.shareholder.equity_price = data.equity_price
                        app.shareholder.equity_price2 = data.equity_price2
                    },

                    //重置
                    resetOrder: function () {

                        location.reload();
                    }
                },

                //自动执行
                mounted: function () {
                    this.initialize();//分公司
                },
            })
        </script>
@include('Admin.public.foot')